<template>
<div style="height: auto">
  <van-card
      :num="item.stock"
      :price="item.price"
      :desc="item.introduction"
      :title="item.name"
      :thumb="item.img"
      v-for="item in this.$store.state.card"
  />
  <div style="margin-top: 20px"><span style="line-height:44px; margin-left: 90px">总计：{{this.$store.state.total}}元</span> <van-button type="danger" style="float: right;margin-right: 15px" @click="createOrder()">提交订单</van-button>
  </div>
</div>
</template>

<script>
import {doCreateOrder} from "@/api/order";

export default {
  name: "card",
  methods:{
    createOrder(){
      if (this.$store.state.total<=0){
        this.$message.error("当前订单没有商品,请添加商品后再提交");
      }else{
        doCreateOrder({orderChildrens:this.$store.state.card,sid: window.localStorage.getItem("sid"),price:this.$store.state.total}).then(res=>{
          if (res.code===200){
            this.$store.state.orderId=res.msg;
            this.$store.state.card=[];
            this.$router.push('pay');
          }
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
